# Validators create type instances for commands
from __future__ import absolute_import
import os
import fnmatch
from cStringIO import StringIO
from tokenize import generate_tokens
import fnmatch
import yaml
import copy
import re
import logging

logger = logging.getLogger('forest.types')

class ConfigurationType(object):
    def __init__(self, config, value):
        pass

    def validate(self):
        raise NotImplementedError

class File(object):
    def __init__(self, value, config):
        self.config = config
        self.value = value

    def get_path(self):
        return self.config.translate_path(self.value)

    def get_filename(self):
        filename = self.config.get_defined_file(self.value)

        if filename is None:
            raise Exception("Path %s doesnt exist from %s. " % (self.value, self.config.get_local_filename()))

        return filename

    def __str__(self):
        return self.value


BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)

COLORS = {
    'WARNING'  : YELLOW,
    'INFO'     : WHITE,
    'DEBUG'    : BLUE,
    'CRITICAL' : YELLOW,
    'ERROR'    : RED,
    'RED'      : RED,
    'GREEN'    : GREEN,
    'YELLOW'   : YELLOW,
    'BLUE'     : BLUE,
    'MAGENTA'  : MAGENTA,
    'CYAN'     : CYAN,
    'WHITE'    : WHITE,
}

RESET_SEQ = "\033[0m"
COLOR_SEQ = "\033[1;%dm"
BOLD_SEQ  = "\033[1m"

# config types

class Path(object):
    def __init__(self, path):
        self.path = path

    def __str__(self):
        return self.path

